package com.blb.utils;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

import com.blb.entity.User;

public class PasswordHelp {

	public static void main(String[] args) {
		//算法名称
        String hashAlgorithmName = "MD5";
        //明文密码
        String credentials = "root";
        //加密次数
        int hashIterations = 1024;
        //盐值
        ByteSource credentialsSalt = ByteSource.Util.bytes("d17fcc12b3ec4f229fb06514a7b9ec9d");
        
        //能过new SimpleHash方法来得到加密后的字符串
        Object obj = new SimpleHash(hashAlgorithmName, credentials, credentialsSalt, hashIterations);
        System.out.println(obj);
    }
	
	/**
	 * 设置新密码
	 * @param user
	 */
	public static void getNewPassword(User user){
		//salt
		String salt = UUIDUtils.getID();
		
		//算法名称
        String hashAlgorithmName = "MD5";
        //加密次数
        int hashIterations = 1024;
        //盐值
        ByteSource credentialsSalt = ByteSource.Util.bytes(salt);
        
        //能过new SimpleHash方法来得到加密后的字符串
        Object obj = new SimpleHash(hashAlgorithmName, user.getPassword(), credentialsSalt, hashIterations);
        
        user.setSalt(salt);
        user.setPassword(obj.toString());
	}
}
